<template>
  <view>
      <!-- 搜索框 -->
      <UgoSearch></UgoSearch>
     <!-- 标签导航 -->
     <u-tabs active-color="#ea4350" bar-width="120" :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
     
     <view class="tab-content">
         <view class="tabs-item" v-for="(item,index) in list" :key="item.name">
             <block v-if="current===index">
                 <navigator class="goods-item" v-for="item1 in goodsList" :key="item1.goods_id" :url="'/pages/goods_detail/goods_detail?goods_id='+item1.goods_id">
			           <view class="left">
				          <u-image width="191rpx" height="191rpx" :src="item1.goods_small_logo"></u-image>
			           </view>
			           <view class="right">
				          <view class="goods-name">{{item1.goods_name}}</view>
				          <view class="goods-price">¥{{item1.goods_price}}</view>
			           </view>  
                 </navigator>
             </block>
         </view>
     </view>
  </view>
</template>

<script>
export default {
		data() {
			return {
				list: [{
					name: '综合'
				}, {
					name: '销量'
				}, {
					name: '价格'
				}],
				current: 0,
                goodsList:[],
                
			}
		},
        onLoad({cid}){
          this.params={
             query: "",
             cid: cid || 1,
             pagenum: 1,
             pagesize: 10,
          }
          this.total=0
          this.getGoodsList()
        },
        // 上拉刷新页面
        onReachBottom(){
            if(this.goodsList.length>=this.total){
                uni.showToast({
                    title:'没有更多数据了~',
                    icon:'none'
                })
            }else{
                this.params.pagenum++
                this.getGoodsList()
            }
        },
        //下拉刷新
        async onPullDownRefresh (){
            this.goodsList=[]
            this.params.pagenum=1
            await this.getGoodsList()
            uni.stopPullDownRefresh()
        },
		methods: {
			change(index) {
				this.current = index;
			},
            async getGoodsList(){
               const res = await this.$u.http.get("/goods/search",this.params)
            //    console.log(res);
               this.goodsList=[...this.goodsList,...res.goods]
               this.total=res.total
            }
		}
	}
</script>

<style lang="scss">
.goods-item {
    width:100%;
    height: 200rpx;
    display: flex;
    margin: 15rpx 0rpx;
    padding: 25rpx,0rpx;
    border-bottom: 1px solid #ccc;
  .left {
    flex: 1;
    display: flex;
    justify-content: center;
  }

  .right {
      flex: 2;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
    .goods-name {
       color: #666;
    }

    .goods-price {
       color: $themeColor;
    }
  }
}
</style>